import 'package:yt_devops/pages/devices/device_tab/device_detail/ems/common/instruct_model.dart';
import 'package:yt_devops/utils/enums.dart';

/// 指令集策略接口
// ignore_for_file: body_might_complete_normally_nullable
abstract class RectangleInstructionSetStrategy {
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  );
}

/// 具体指令策略
/// 启动系统
class StartingSystem implements RectangleInstructionSetStrategy {
  @override
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  ) {
    requestParams!.deviceId = deviceId;
    requestParams.input = {
      'sysStart': '1',
    };
    requestParams.serviceId = RectangleEmsTriggerInstrucType.sysStart.value;
    return {
      "deviceId": requestParams.deviceId,
      "serviceId": requestParams.serviceId,
      "input": requestParams.input,
    };
  }
}

/// 停止系统
class StopingSystem implements RectangleInstructionSetStrategy {
  @override
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  ) {
    requestParams!.deviceId = deviceId;
    requestParams.input = {
      'sysStop': '1',
    };
    requestParams.serviceId = RectangleEmsTriggerInstrucType.sysStop.value;
    return {
      "deviceId": requestParams.deviceId,
      "serviceId": requestParams.serviceId,
      "input": requestParams.input,
    };
  }
}

/// 系统复位
class ResettingSystem implements RectangleInstructionSetStrategy {
  @override
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  ) {
    requestParams!.deviceId = deviceId;
    requestParams.input = {
      'sysReset': '1',
    };
    requestParams.serviceId = RectangleEmsTriggerInstrucType.sysReset.value;
    return {
      "deviceId": requestParams.deviceId,
      "serviceId": requestParams.serviceId,
      "input": requestParams.input,
    };
  }
}

/// BMS主接触器闭合
class BMSMainContactorClosed implements RectangleInstructionSetStrategy {
  @override
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  ) {
    requestParams!.deviceId = deviceId;
    requestParams.input = {
      'bmsClose': '1',
    };
    requestParams.serviceId = RectangleEmsTriggerInstrucType.bmsClose.value;
    return {
      "deviceId": requestParams.deviceId,
      "serviceId": requestParams.serviceId,
      "input": requestParams.input,
    };
  }
}

/// BMS主接触器断开
class BMSMainContactorDisconnected implements RectangleInstructionSetStrategy {
  @override
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  ) {
    requestParams!.deviceId = deviceId;
    requestParams.input = {
      'bmsBreak': '1',
    };
    requestParams.serviceId = RectangleEmsTriggerInstrucType.bmsBreak.value;
    return {
      "deviceId": requestParams.deviceId,
      "serviceId": requestParams.serviceId,
      "input": requestParams.input,
    };
  }
}

/// 手/自动切换
class ManualAutomaticSwitching implements RectangleInstructionSetStrategy {
  @override
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  ) {
    requestParams!.deviceId = deviceId;
    requestParams.input = {
      'manualAutomaticSwitch': '1',
    };
    requestParams.serviceId = RectangleEmsTriggerInstrucType.operateModel.value;
    return {
      "deviceId": requestParams.deviceId,
      "serviceId": requestParams.serviceId,
      "input": requestParams.input,
    };
  }
}

/// 离并网切换
class ParallelOffGridSwitching implements RectangleInstructionSetStrategy {
  @override
  Map<String, dynamic>? trigger(
    String? deviceId,
    SettingReqParams? requestParams,
  ) {
    requestParams!.deviceId = deviceId;
    requestParams.input = {
      'parallelOffGridMode': '1',
    };
    requestParams.serviceId = RectangleEmsTriggerInstrucType.operateModel.value;
    return {
      "deviceId": requestParams.deviceId,
      "serviceId": requestParams.serviceId,
      "input": requestParams.input,
    };
  }
}
